package com.paipaideli.ui.mine.safety;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jakewharton.rxbinding2.view.RxView;
import com.paipaideli.R;
import com.paipaideli.common.base.BasePresenterActivity;
import com.paipaideli.common.utils.ToastUtil;
import com.paipaideli.common.utils.preferrnces.FastData;
import com.paipaideli.ui.MainActivity;
import com.paipaideli.ui.login.LoginActivity;
import com.paipaideli.ui.mine.realname.RealNameActivity;
import com.paipaideli.ui.mine.safety.event.LogoutEvent;
import com.paipaideli.ui.product.ProductDetailActivity;

import org.greenrobot.eventbus.EventBus;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by 安全中心
 */
public class SafetyCenterActivity extends BasePresenterActivity implements View.OnClickListener {

    Unbinder unbinder;
    @BindView(R.id.top_back)
    RelativeLayout top_back;
    @BindView(R.id.top_title)
    TextView top_title;
    @BindView(R.id.lin_safety_smrz)
    LinearLayout lin_safety_smrz;
    @BindView(R.id.rel_safety_pwd)
    RelativeLayout rel_safety_pwd;
    @BindView(R.id.rel_safety_paypwd)
    RelativeLayout rel_safety_paypwd;
    @BindView(R.id.rel_safety_bank)
    RelativeLayout rel_safety_bank;
    @BindView(R.id.btn_safety_logout)
    Button btn_safety_logout;

    private String certificationStatu;


    @Override
    public int getContentView() {
        return R.layout.activity_safety;
    }

    @Override
    public void initView() {
        unbinder = ButterKnife.bind(this);
        top_title.setText("安全中心");
        try {
            certificationStatu = getIntent().getStringExtra("certificationStatu");
            if (certificationStatu.equals("1")) {
                lin_safety_smrz.setVisibility(View.GONE);
            } else {
                lin_safety_smrz.setVisibility(View.VISIBLE);
            }
        } catch (Exception e) {
            certificationStatu = "0";
        }
        top_back.setOnClickListener(this::onClick);
//        lin_safety_smrz.setOnClickListener(this::onClick);
//        rel_safety_pwd.setOnClickListener(this::onClick);
//        rel_safety_bank.setOnClickListener(this::onClick);
        btn_safety_logout.setOnClickListener(this::onClick);

        //实名认证
        RxView.clicks(lin_safety_smrz)
                .throttleFirst(1, TimeUnit.SECONDS)
                .subscribe(o -> {
                    Intent intent = new Intent(SafetyCenterActivity.this, RealNameActivity.class);
                    startActivity(intent);
                }, throwable -> {
                });

        //修改密码
        RxView.clicks(rel_safety_pwd)
                .throttleFirst(1, TimeUnit.SECONDS)
                .subscribe(o -> {
                    Intent intent = new Intent(SafetyCenterActivity.this, ModifyPwdActivity.class);
                    startActivity(intent);
                }, throwable -> {
                });

        //添加银行卡
        RxView.clicks(rel_safety_bank)
                .throttleFirst(1, TimeUnit.SECONDS)
                .subscribe(o -> {
                    Intent intent = new Intent(SafetyCenterActivity.this, MyBankActivity.class);
                    intent.putExtra("which", "2");
                    startActivity(intent);
                }, throwable -> {
                });
    }

    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.top_back:
                finish();
                break;
            case R.id.btn_safety_logout:
                intent = new Intent(SafetyCenterActivity.this, LoginActivity.class);
                FastData.setIsLogin(false);
                startActivity(intent);
                finish();
                LogoutEvent logoutEvent = new LogoutEvent();
                logoutEvent.setCheck(0);
                EventBus.getDefault().post(logoutEvent);
                break;
        }

    }
}
